package com.myq.lawyermanager.dongao.controller;

import com.myq.lawyermanager.dongao.entity.Lawyer;
import com.myq.lawyermanager.dongao.service.LawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 律师控制器
 */
@Controller
public class LawyerController {

    @Autowired
    LawyerService lawyerService;
    @RequestMapping("/modify")
    public String modifyLawyer(Lawyer lawyer){
        lawyerService.modifyLawyer(lawyer);
//        return "../static/success";
        return "redirect:/show";
    }
    @RequestMapping("/get")
    public String getLawyerById(Model model,int lawyerid){
        Lawyer lawyer = lawyerService.findLawyerById(lawyerid);
//        把查询得到的对象保存起来，传递到网页上
        model.addAttribute("lawyer", lawyer);
        return "../static/modifyLawyer";
    }

    @RequestMapping("/del")
    public String delLawyer(int lawyerid){
        lawyerService.removeLawyer(lawyerid);
        return "../static/success";
    }
    @RequestMapping("/show")
    public String showLawyer(Model model){
        List<Lawyer> lawyerList = lawyerService.findLawyer();
//        把lawyer List 传输到网页上
        model.addAttribute("lawList", lawyerList);
//        displayLawyer 是网页displayLawyer.html
        return "../static/displayLawyer";
    }

    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        lawyerService.addLawyer(lawyer);
        //success 使一个网页success.html
        return "../static/success";
    }
}
